package com.hapzxb.consumer.controller;

import com.hapzxb.consumer.bean.Department;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.client.RestTemplate;

import java.util.List;

@RestController
@RequestMapping("consumer/department")
public class DepartmentController {
    @Autowired
    private RestTemplate restTemplate;

    @PostMapping("/save")
    public boolean saveHandle(Department department){
        String url = "http://localhost:8081/provider/department/save";
        return restTemplate.postForObject(url,department,Boolean.class);
    }

    @DeleteMapping("/del/{id}")
    public void delHandle(@PathVariable("id") int id){
        String url = "http://localhost:8081/provider/department/del/"+id;
        restTemplate.delete(url);
    }

    @PutMapping("/update")
    public void updateHandle(Department department){
        String url = "http://localhost:8081/provider/department/update/";
        restTemplate.put(url,department);
    }

    @GetMapping("/get/{id}")
    public Department getHandle(@PathVariable("id") int id){
        String url = "http://localhost:8081/provider/department/get/"+id;
        return restTemplate.getForObject(url,Department.class);
    }

    @PostMapping("/list")
    public List<Department> listHandle(){
        String url = "http://localhost:8081/provider/department/get/";
        return restTemplate.getForObject(url,List.class);
    }
}

